home *** CD-ROM | disk | FTP | other *** search
/ stazsoftware.com / www.stazsoftware.com.tar / www.stazsoftware.com / futurebasic / sample-code / DisplayInFinder.sit / Display In Finder
Text File  |  2005-05-11  |  3KB  |  116 lines

  1.  
  2. '~'A
  3. '                             Runtime : Rntm Appearance.Incl
  4. '                                 CPU : Carbon
  5. '                          CALL Req'd : Off
  6. '                    No Re-DIM'd Vars : On
  7. '                     DIM'd Vars Only : On
  8. '                        Debug Labels : On
  9. '                       Register Vars : On
  10. '~'B
  11.  
  12. /*
  13.      this shows how to display a file [via filespec] in the finder
  14.      from your application. very cool!
  15.      
  16.      original code by waverly edwards
  17.  
  18.      this is the code used in the editor when you control click an
  19.      item in the editor's project window to view it in the finder.
  20.  
  21.      items collected into a single file for upload by staz on 11 may 05 by staz
  22. */
  23.  
  24. end globals
  25.  
  26. _kAEMiscStandards              = _"misc"
  27. _kAEMakeObjectsVisible         = _"mvis"
  28. _kAECanSwitchLayer             = 0x00000040/* interaction may switch layer */
  29. _kAEAlwaysInteract             = 0x00000030
  30.  
  31. register off
  32. local mode
  33. local fn findProcess( type as OSType, creator as OSType, psnPtr as ptr to ProcessSerialNumber )
  34. '~'9
  35. /*
  36.      if process of specified type and creator is running, return _noErr and
  37.      fill in the ProcessSerialNumber;  else return _procNotFound or _paramErr as appropriate
  38. */
  39. dim processInfo as ProcessInfoRec
  40. dim retCode as short
  41.  
  42. processInfo.processInfoLength = sizeof( ProcessInfoRec ) // Set up the process info rec
  43. processInfo.processName       = _nil
  44. processInfo.processAppSpec    = _nil
  45. psnPtr.highLongOfPSN = 0 //  to get first process in the list
  46. psnPtr.lowLongOfPSN  = 0
  47. while ( fn GetNextProcess( #psnPtr ) == _noErr ) // Index the list until process found or all searched
  48. long if ( fn GetProcessInformation( #psnPtr, processInfo ) )
  49. retCode = _paramErr
  50. exit fn
  51. end if
  52. long if ( processInfo.processSignature == creator ) and ( processInfo.processType == type )
  53. retCode = _noErr
  54. exit fn
  55. end if
  56. wend
  57. retCode = _procNotFound
  58. end fn = retCode
  59.  
  60. local mode
  61. local fn showFileInFinder(inSpec as ^FSSpec)
  62. '~'9
  63. register on
  64. dim as ProcessSerialNumber finderPSN
  65. dim as AppleEvent aEvent, reply
  66. dim as AEDesc  addrDesc
  67. dim as OSErr  err,ignore
  68.  
  69. // OUCH! That took a long time to work out
  70.  
  71. // locate the running Finder
  72. err = fn findProcess(_"FNDR",_"MACS",finderPSN)
  73. if (err) then  exit "bail"
  74.  
  75. // create an address descriptor for the Finder
  76. err = fn AECreateDesc(_typeProcessSerialNumber, finderPSN, sizeof(finderPSN), addrDesc)
  77. if (err) then  exit "bail"
  78.  
  79. // create the event, addressed to the Finder
  80. err = fn AECreateAppleEvent(_kAEMiscStandards, _kAEMakeObjectsVisible, addrDesc,_kAutoGenerateReturnID, _kAnyTransactionID, aEvent)
  81. if (err) then  exit "bail"
  82.  
  83. // add the direct parameter
  84. err = fn AEPutParamPtr(aEvent, _keyDirectObject, _typeFSS, #inSpec, sizeof(FSSpec))
  85. if (err) then  exit "bail"
  86.  
  87. // send the event
  88. err = fn AESend(aEvent,reply,_kAECanSwitchLayer+_kAEAlwaysInteract+_kAENoReply,_kAENormalPriority,_kAEDefaultTimeout,_nil,_nil)
  89. if (err) then  exit "bail"
  90.  
  91. // bring Finder to front at next opportunity
  92. err = fn SetFrontProcess(finderPSN)
  93.  
  94. "bail"
  95. ignore = fn AEDisposeDesc( aEvent )
  96. ignore = fn AEDisposeDesc( reply )
  97. ignore = fn AEDisposeDesc( addrDesc )
  98.  
  99. end fn = err
  100.  
  101.  
  102.  
  103. '~'6
  104. // example -- here's how to use it
  105. '~'6
  106. dim as fsspec fs
  107. dim as str255 fName
  108. gFBUseNavServices = _zTrue
  109. fName = files$ ( _fsSpecOpen , , "Select a file, I'll show it to you in the Finder" , fs )
  110.  
  111. long if fName[0]
  112. fn showFileInFinder ( fs )
  113. end if
  114.  
  115.  
  116.